/*
* This file is a part of the open-eBackup project.
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file, You can obtain one at
* http://mozilla.org/MPL/2.0/.
*
* Copyright (c) [2024] Huawei Technologies Co.,Ltd.
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*/
#ifndef OBS_PREFIX_INFO_H
#define OBS_PREFIX_INFO_H
#include <string>
#include <vector>
#include "Module/src/common/JsonHelper.h"
#include "utils/PluginUtilities.h"

namespace OBSPlugin {
    class PrefixInfo {
        public:
            PrefixInfo() = default;
            PrefixInfo(const std::string& bucketName, const std::string& parentPrefix,
                const std::string& subPrefix, bool isPrefixLevelObject)
            {
                this->bucketName = bucketName;
                if (!parentPrefix.empty()) {
                    this->parentPrefixFilter.push_back(parentPrefix);
                }
                if (!subPrefix.empty()) {
                    this->subPrefixs.push_back(subPrefix);
                }
                this->isPrefixLevelObject = isPrefixLevelObject;
            }
            std::string buildKey() const
            {
                std::string tempKey;
                tempKey += bucketName;
                tempKey += parentPrefixFilter.empty() ? "" : parentPrefixFilter.front();
                tempKey += subPrefixs.empty()? "" : subPrefixs.front();
                tempKey += isPrefixLevelObject ? "1" : "0";
                return tempKey;
            }

            std::string buildMergeKey() const
            {
                std::string tempKey;
                tempKey += bucketName;
                tempKey += parentPrefixFilter.empty() ? "" : parentPrefixFilter.front();
                tempKey += isPrefixLevelObject ? "1" : "0";
                return tempKey;
            }
            bool Equal(const PrefixInfo& other) const
            {
                if (bucketName != other.bucketName || isPrefixLevelObject != other.isPrefixLevelObject ||
                    !PluginUtilities::VectorStrEqual(parentPrefixFilter, other.parentPrefixFilter) ||
                    !PluginUtilities::VectorStrEqual(subPrefixs, other.subPrefixs)) {
                    return false;
                }
                return true;
            }

            std::string bucketName;
            bool isPrefixLevelObject = false; // true:表示对列举层级上的Object进行列举；
                                            // false:表示仅对指定prefix下Object进行列举,仅在多节点并行开关开启时赋值。默认为false.
            std::vector<std::string> parentPrefixFilter;
            std::vector<std::string> subPrefixs;

            BEGIN_SERIAL_MEMEBER
            SERIAL_MEMEBER(bucketName)
            SERIAL_MEMEBER(isPrefixLevelObject)
            SERIAL_MEMEBER(parentPrefixFilter)
            SERIAL_MEMEBER(subPrefixs)
            END_SERIAL_MEMEBER
        };
}
#endif
